package com.itheima.exerciseTest.method20_29.method21;

import java.io.*;

public class Test2 {
    public static void main(String[] args) throws ClassNotFoundException, IOException,  ClassNotFoundException {
        User u1 = new User("itheima001", "123456", 23);
        User u2 = new User("itheima002", "697453", 24);
        User u3 = new User("itheima003", "142345", 25);

        // 创建对象序列化流
        ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("backBurner\\j.txt"));
        oos.writeObject(u1);
        oos.writeObject(u2);
        oos.writeObject(u3);
        oos.close();

        // 创建对象反序列化流
        ObjectInputStream ois = new ObjectInputStream(new FileInputStream("backBurner\\j.txt"));
        while (true) {

            try {
                Object o = ois.readObject();
                User u = (User) o;
                System.out.println(u);
            } catch (IOException e) {
                break;
            }

        }
        ois.close();

    }
}
